#ifndef ir_h
#define ir_h

/**
 * @defgroup nxbot_ir IR Library
 * @ingroup nxbot_low_level
 * @code #include <ir.h> @endcode
 * @brief Interrupt IR library for checking the state of the %ir sensors in NXBOT. 
 *
 * This module uses the I/O pins of the ATmega1281 microcontroller for accesing the IR modules of NXBot. Each IR module is controlled by two signals:
 * <i>Emitter</i> and <i>Receiver</i>. The emitter signal should be modulated. The carrier signal uses a 40 kHz frequenzy, which is generated by 
 * external hardware. The modulated signal should fulfill a period time of 1600 us, where in the first 600 us the signal should stay HIGH (5V), and in 
 * the remaining 1000 us the signal should stay LOW (0V). In order to do that, the modulated signal is generated by the timer5 of the microcontroller. 
 * It uses the <i>Output Compare</i> configuration in order to generate a signal with this specific duty cicle. For more information, see datasheet 
 * of GP1UD28YK device, which is the receiver used in the %IR hardware. Because of the use of timer5, the readings will only be done when interrupts 
 * are active. Therefore, it is necessary to enable interrupts, for example via the <i>sei()</i> function.
 */
 
/**@{*/

/**
 * @brief   Constant to access the IR located at -80°. 
 * @see ir_activate
 */
#define IR_80N 0
/**
 * @brief   Constant to access the IR located at -45°. 
 * @see ir_activate
 */
#define IR_45N 1
/**
 * @brief   Constant to access the IR located at -10°. 
 * @see ir_activate
 */
#define IR_10N 2
/**
 * @brief   Constant to access the IR located at 10°. 
 * @see ir_activate
 */
#define IR_10P 3
/**
 * @brief   Constant to access the IR located at 45°. 
 * @see ir_activate
 */
#define IR_45P 4
/**
 * @brief   Constant to access the IR located at 80°. 
 * @see ir_activate
 */
#define IR_80P 5



//unsigned char ir_readAll(void);

/**
 * @brief Hardware initialization for the %ir module.
 *
 * Configures Emitter pins as outputs and Receiver pins as inputs. Disables all IRs and configures timer5 in <i>Output Compare</i> mode
 *
 */
void ir_init(void );

/**
 * @brief Read the IR states.
 *
 * Reads the state of all active IRs. Remember to activate the IRs before reading its state. This is done by using ir_activate() function
 * for activating one IR at a time. If you want to activate all of them, use ir_activateAll() instead.
 *
 * @return A byte where the the first four bits represent the bumpers state:
 *					- @b Bit0:
 *              <br> IR located at -80°.
 *					- @b Bit1:		
 *              <br> IR located at -45°.
 *					- @b Bit2:		
 *              <br> IR located at -10°.
 *					- @b Bit3:		
 *              <br> IR located at +10°.
 *					- @b Bit4:		
 *              <br> IR located at +45°.
 *					- @b Bit5:		
 *              <br> IR located at +80°.
 */
unsigned char ir_read(void);

/**
 * @brief (De)activates a specific %IR module.
 *
 * The activation permits updating of data coming from this sensor.
 * @param ir The desired %IR to be (de)activated. You should use the constants denoted by IR_(ANGLE), e.g IR_80N.
 * @param en Defines activation or deactivation of %IR. You should use the constants ON and OFF defined globally in the Makefile.
 *
 */
void ir_activate(unsigned char ir,unsigned char en);

/**
 * @brief (De)activates all %IR modules.
 *
 * The activation permits updating of data coming from all sensors.
 * @param en Defines activation or deactivation of all %IRs. You should use the constants ON and OFF defined globally in the Makefile.
 *
 */
void ir_activateAll(unsigned char en);

/**@}*/

#endif
